package com.dliu.javadesign.create.builder;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author yanglei
 * date 2021/3/29 17:18
 */
public class Meal {
    private List<Item> itemList = new ArrayList<>();

    public void addItem(Item item){
        itemList.add(item);
    }

    public double getCost(){
        Optional<Double> reduce = itemList.stream().map(Item::price).collect(Collectors.toList()).stream().reduce((result, item) -> result + item);
        System.out.println("总价：" + reduce.get());
        return reduce.get();
    }

    public void showItems(){
        for (Item item : itemList) {
            System.out.print("Name : "+item.name());
            System.out.print(", Packing : "+item.doPack().pack());
            System.out.println(", Price : "+item.price());
        }
    }
}
